package com.agile.leetcode.chain;

import java.util.ArrayList;
import java.util.List;

/**
 * @author CZK
 * @date 2022/7/5 16:45
 */
public class FilterChain implements Filter{
    List<Filter> list=new ArrayList<>();
    private String target;
    int index=0;
    @Override
    public void doFilter(Request request, Response response, FilterChain chain) {
        if (index<list.size()){
            Filter filter = list.get(index);
            index++;
            filter.doFilter(request,response,chain);
        }else {
            System.out.println(request.getParam());
            System.out.println(response.getMsg());
            System.out.println(chain.getTarget());
        }
    }
    public void setTarget(String target){
        this.target=target;
    }
    public void addFilter(Filter filter) {
        list.add(filter);
    }

    public String getTarget() {
        return target;
    }
}
